package com.mvd.app.activity;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.ac2020.QingDaoPhotoActivity;
import com.mvd.app.ac_wenzhou.An_Huan_HomeActivity;
import com.mvd.app.ac_wenzhou.DiGouActivity;
import com.mvd.app.adapter.CarsInforListAdapter;
import com.mvd.app.adapter.CarsInforListAdapter2;
import com.mvd.app.adapter.MyAccountModeListAdapter;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.FileUtils;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.An_Huan_Model;
import com.mvd.app.model.CarCheckItemsModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.DownLineModel;
import com.mvd.app.model.HuanBaoModel;
import com.orhanobut.logger.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @Description: 待检车辆列表
 */
public class DaiJianCarsActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    @BindView(R.id.title_btn_left)
    ImageButton titleBtnLeft;
    @BindView(R.id.title_btn_left_txt)
    Button titleBtnLeftTxt;
    @BindView(R.id.title_txt)
    TextView titleTxt;
    @BindView(R.id.iv_headtip)
    ImageView ivHeadtip;
    @BindView(R.id.title_btn_right_txt)
    Button titleBtnRightTxt;
    @BindView(R.id.title_btn_right)
    ImageButton titleBtnRight;
    @BindView(R.id.ac_daijian_et_search2)
    EditText acDaijianEtSearch2;
    @BindView(R.id.ac_daijian_btn_search2)
    Button acDaijianBtnSearch2;
    @BindView(R.id.ac_daijian_bt_type2)
    Button acDaijianBtType2;
    @BindView(R.id.list_shequgonggao_baoxiu)
    ListView listShequgonggaoBaoxiu;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    @BindView(R.id.ac_daijian_btn_chongxin_xiaxian)
    Button acDaijianBtnChongxinXiaxian;
    @BindView(R.id.ac_set_view_m_2_image)
    TextView acSetViewM2Image;
    @BindView(R.id.ac_daijian_btn_buchuan_zhaopian)
    Button acDaijianBtnBuchuanZhaopian;
    @BindView(R.id.ac_daijian_lay_ll_statement)
    LinearLayout acDaijianLayStatament;

    private int CHECK_MODE = 0;//检测模式 0:外检  1：路试 2：底盘动态
    private List<CarsInforModel> carsInforModelList = new ArrayList<CarsInforModel>();
    private List<CarsInforModel> carsInforModelList_2 = new ArrayList<CarsInforModel>();
    private List<CarsInforModel> searChCarsList_one = new ArrayList<CarsInforModel>();//查询的列表
    private List<CarsInforModel> searChCarsList_two = new ArrayList<CarsInforModel>();//查询的列表
    private List<CarsInforModel> searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
    private List<HuanBaoModel> huanBao_carsInforModelList = new ArrayList<HuanBaoModel>();//环保队列
    private List<An_Huan_Model> an_huan_carsList = new ArrayList<An_Huan_Model>();//安检-环保-并集
    private List<An_Huan_Model> an_huan_adapterList = new ArrayList<An_Huan_Model>();//安检-环保-最终合集
    //adapter的过滤后的数据列表
//    private List<CarsInforModel> adapterCarsList = new ArrayList<CarsInforModel>();
    private CarsInforListAdapter carsInforListAdapter;
    public DaiJianCarsActivity instances = null;
    private String carNO = null;
    private List<CarCheckItemsModel> carCheckItemModelList = new ArrayList<CarCheckItemsModel>();
    //待检测车辆要检测的项目的列表
    private String CURRENT_CHECK_MODE = "";//当前检测模式
    private String Login_name = "", login_IDNumber, login_username;//当前登录的检测员的名字
    private DownLineModel downLineModel;
    private Handler handler = new Handler();
    MyRunnable myRunnable = new MyRunnable();//定义MyRunnable的对象；
    private CarsInforListAdapter2 carsInforListAdapter2;
    private boolean userRightCheckMode = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dai_jian_cars_2);
        ButterKnife.bind(this);
        setTopTitle(R.string.activity_daijian_car_list);
        setHideLeftBtn();
        instances = this;
        UtilsLog.e("SharedPreferencesUtils.getCode2List(this)===" + SharedPreferencesUtils.getCode2List(this));
        userRightCheckMode = getIntent().getExtras().getBoolean("userRightCheckMode", false);
        UtilsLog.e("DaiJianCarsActivity---userRightCheckMode=====" + userRightCheckMode);
        Login_name = getIntent().getExtras().getString("login_UserID", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        login_username = getIntent().getExtras().getString("login_username", "");
        UtilsLog.e("login_IDNumber=Login_name=" + login_IDNumber + "=====" + Login_name);
        CHECK_MODE = BaseApplication.JIANCE_MODE;
        UtilsLog.e(" BaseApplication.JIANCE_MODE-DaiJianCarsActivity==" + BaseApplication.JIANCE_MODE);
        listShequgonggaoBaoxiu.setOnItemClickListener(this);
        pop_type();
        if (userRightCheckMode) {
            setRightTxt("补传照片", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(DaiJianCarsActivity.this, RecheckPhotoListActivity.class);
                    i.putExtra("login_UserID", Login_name);
                    i.putExtra("login_username", login_username);
                    i.putExtra("login_IDNumber", login_IDNumber);
                    startActivity(i);
                }
            });
        }

        switch (BaseApplication.JIANCE_MODE) {
            //检测模式 0:外检  F1 1：路试 R1 2：底盘动态 DC
            case 0:
                CURRENT_CHECK_MODE = "F1";
                break;
            case 1:
                CURRENT_CHECK_MODE = "R1";
                break;
            case 2:
                CURRENT_CHECK_MODE = "DC";
                break;
            case 6:
                CURRENT_CHECK_MODE = "C1";
                break;
            case 8:
                CURRENT_CHECK_MODE = "F1";
                break;
        }
        try {
            String filePath = null;
            filePath = Environment.getExternalStorageDirectory() + "/PDASetting/setting.txt";
            String reCheckPhotoSetting = FileUtils.readTextFile(new File(filePath)).trim();
            Log.e("tag", "复检拍照设置==" + reCheckPhotoSetting);
//            if (!TextUtils.isEmpty(reCheckPhotoSetting)) {
//                if (reCheckPhotoSetting.equals("123456")) {
//                    acDaijianBtType2.setVisibility(View.GONE);
//                    Log.e("tag", "复检拍照设置=======隐藏=");
//                } else {
//                    Log.e("tag", "复检拍照设置====11===显示=");
//                    acDaijianBtType2.setVisibility(View.VISIBLE);
//                }
//            } else {
//                Log.e("tag", "复检拍照设置====22===显示=");
//                acDaijianBtType2.setVisibility(View.VISIBLE);
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        acDaijianLayStatament.setVisibility(View.GONE);
        acDaijianBtnChongxinXiaxian.setVisibility(View.GONE);
//        //重新下线与补传照片的开关显示与隐藏
//        if (SharedPreferencesUtils.getChongXinXiaXianStatement(instances) == false &&
//                SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances) == false) {
//            acDaijianLayStatament.setVisibility(View.GONE);
//        } else {
//            acDaijianLayStatament.setVisibility(View.VISIBLE);
//        }
//        Log.e("tag", "重新下线设置==" + SharedPreferencesUtils.getChongXinXiaXianStatement(instances));
//        Log.e("tag", "补传照片设置==" + SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances));
//        if (SharedPreferencesUtils.getChongXinXiaXianStatement(instances)) {
//            acDaijianBtnChongxinXiaxian.setVisibility(View.VISIBLE);
//        } else {
//            acDaijianBtnChongxinXiaxian.setVisibility(View.GONE);
//        }

        if (SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances)) {
            acDaijianBtnBuchuanZhaopian.setVisibility(View.VISIBLE);
        } else {
            acDaijianBtnBuchuanZhaopian.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.ac_daijian_btn_search2, R.id.ac_daijian_bt_type2, R.id.fab,
            R.id.ac_daijian_btn_chongxin_xiaxian, R.id.ac_daijian_btn_buchuan_zhaopian})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_daijian_btn_search2:
                //查询
                carNO = acDaijianEtSearch2.getText().toString().trim();
                if (!TextUtils.isEmpty(carNO)) {
                    CommonUtils.showLoadingDialog(instances, "加载中...");
                    schearCarByNO(carNO);

//                    downLineModel = new DownLineModel();
//                    downLineModel.setType("0");
//                    downLineModel.setPlateNO(carNO);
//                    searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
//                    for (int i = 0; i < 2; i++) {
//                        if (i == 0) {
//                            downLineModel.setStatus("0");
//                            getDataSearchCarsByNO(downLineModel);
//                        } else if (i == 1) {
//                            downLineModel.setStatus("1");
//                            getDataSearchCarsByNO(downLineModel);
//                        }
//                    }
                } else {
                    Toast.makeText(instances, "车牌号码不能为空", Toast
                            .LENGTH_LONG).show();
                }

//                if (adapterCarsList != null && adapterCarsList.size() > 0) {
//                    searChCarsList = new ArrayList<CarsInforModel>();
//                    for (int i = 0; i < adapterCarsList.size(); i++) {
//                        String cno = (adapterCarsList.get(i).getPlateRegion() + adapterCarsList.get
//                                (i).getPlateNO()).toLowerCase();
//                        if (cno.contains(carNO.toLowerCase())) {
//                            searChCarsList.add(adapterCarsList.get(i));
//                        }
//                    }
//                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
//                            searChCarsList, CURRENT_CHECK_MODE);
//                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
//                }

                break;
            case R.id.ac_daijian_bt_type2:
//                pop2.showAsDropDown(acDaijianBtType2);
//                //跳转复检拍照界面
//                Intent intent = new Intent(this, RecheckPhotoListActivity.class);
//                startActivity(intent);
                break;
            case R.id.fab:
                if (SharedPreferencesUtils.getAutoRefresh(this)) {
//                    getData(0);
                    refreshData();
                } else {
                    carNO = acDaijianEtSearch2.getText().toString().trim();
                    if (!TextUtils.isEmpty(carNO)) {
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                        downLineModel = new DownLineModel();
                        downLineModel.setType("0");
                        downLineModel.setPlateNO(carNO);
                        searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
                        for (int i = 0; i < 2; i++) {
                            if (i == 0) {
                                downLineModel.setStatus("0");
                                getDataSearchCarsByNO(downLineModel);
                            } else if (i == 1) {
                                downLineModel.setStatus("1");
                                getDataSearchCarsByNO(downLineModel);
                            }
                        }
                    } else {
                        Toast.makeText(instances, "车牌号码不能为空", Toast
                                .LENGTH_LONG).show();
                    }
                }
                break;
            case R.id.ac_daijian_btn_chongxin_xiaxian:
                //重新下线
                Intent i = new Intent(DaiJianCarsActivity.this, DownLineCarsListActivity.class);
                startActivity(i);
                break;
            case R.id.ac_daijian_btn_buchuan_zhaopian:
                //跳转复检拍照界面,补传照片
                Intent intent = new Intent(this, RecheckPhotoListActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//        CarsInforModel carsInforModel = (CarsInforModel) parent.getAdapter().getItem(position);
        An_Huan_Model carsInforModel = (An_Huan_Model) parent.getAdapter().getItem(position);
        int Is_An_Huan = carsInforModel.getIsAnHuan();
        UtilsLog.e("An_Huan_Model=33=" + carsInforModel.toString());
        Intent intent2 = null;
        //检测模式 0:外检  1：路试 2：底盘动态
        if (CHECK_MODE == 0) {
            //外检
            intent2 = new Intent(DaiJianCarsActivity.this, An_Huan_HomeActivity.class);
        } else if (CHECK_MODE == 1) {
            //路试
            if (Is_An_Huan == 0 || Is_An_Huan == 2) {
                intent2 = new Intent(DaiJianCarsActivity.this, RoadTestActivity.class);
            } else {
                Toast.makeText(instances, "环保不需检测", Toast
                        .LENGTH_LONG).show();
            }
        } else if (CHECK_MODE == 2) {
            //底盘动态
            if (Is_An_Huan == 0 || Is_An_Huan == 2) {
                intent2 = new Intent(DaiJianCarsActivity.this, DiPanDongTaiActivity.class);
            } else {
                Toast.makeText(instances, "环保不需检测", Toast
                        .LENGTH_LONG).show();
            }
        } else if (CHECK_MODE == 6) {
            //地沟
            if (Is_An_Huan == 0 || Is_An_Huan == 2) {
                intent2 = new Intent(DaiJianCarsActivity.this, DiGouActivity.class);
            } else {
                Toast.makeText(instances, "环保不需检测", Toast
                        .LENGTH_LONG).show();
            }
        } else if (CHECK_MODE == 8) {
            //青岛
            if (Is_An_Huan == 0 || Is_An_Huan == 2) {
                intent2 = new Intent(DaiJianCarsActivity.this, QingDaoPhotoActivity.class);
            } else {
                Toast.makeText(instances, "环保不需检测", Toast
                        .LENGTH_LONG).show();
            }
        }
        if (intent2 != null) {
            intent2.putExtra("model_CarsInforModel", carsInforModel);
            intent2.putExtra("check_mode", CHECK_MODE);
            intent2.putExtra("Login_name", Login_name);
            intent2.putExtra("login_IDNumber", login_IDNumber);
            startActivity(intent2);
        }
    }

    private View view2;
    private LinearLayout parent22;
    private PopupWindow pop2 = null;
    private ListView listview_modes;
    private List<String> typeList = new ArrayList<String>();
    MyAccountModeListAdapter myTypeAdapter;

    private void pop_type() {
        for (int i = 0; i < Constants.JIANCE_TYPE.length; i++) {
            typeList.add(i, Constants.JIANCE_TYPE[i]);
        }
        pop2 = new PopupWindow(this);
        view2 = getLayoutInflater().inflate(R.layout.item_pop_type,
                null);
        pop2.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop2.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop2.setBackgroundDrawable(new BitmapDrawable());
        pop2.setFocusable(true);
        pop2.setOutsideTouchable(true);
        pop2.setContentView(view2);
        parent22 = (LinearLayout) view2.findViewById(R.id.ac_daijian_car2_parent);
        listview_modes = (ListView) view2.findViewById(R.id.ac_daijian_car2_listview);
        if (typeList != null && typeList.size() > 0) {
            myTypeAdapter = new MyAccountModeListAdapter(DaiJianCarsActivity.this, typeList);
            listview_modes.setAdapter(myTypeAdapter);
            listview_modes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int position, long arg3) {
//                Toast.makeText(LoginActivity.this, "====" + strModes.get(position),
//                        Toast.LENGTH_SHORT).show();
                    acDaijianBtType2.setText(typeList.get(position));
                    pop2.dismiss();
                }
            });
        }


        parent22.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop2.dismiss();
            }
        });
    }

    private void getData(int type) {
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(this))) {
            if (CommonUtils.isOnline(this)) {
                if (type == 0) {
                    getDataCarsListByMode();
                } else if (type == 1) {
                    getDataCarsListHuanBao();
                }
            } else {
                Toast.makeText(this, getResources().getString(R.string.network_error), Toast.LENGTH_LONG)
                        .show();
            }
        } else {
            Toast.makeText(this, "请设置IP与端口号", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        acDaijianEtSearch2.setText("");
        UtilsLog.e("是否自动刷新==" + SharedPreferencesUtils.getAutoRefresh(this));
        if (SharedPreferencesUtils.getAutoRefresh(this)) {
            refreshData();
//            refreshData();
        } else {
            carNO = acDaijianEtSearch2.getText().toString().trim();
            if (!TextUtils.isEmpty(carNO)) {
                CommonUtils.showLoadingDialog(instances, "加载中...");
                schearCarByNO(carNO);
//                downLineModel = new DownLineModel();
//                downLineModel.setType("0");
//                downLineModel.setPlateNO(carNO);
//                searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
//                for (int i = 0; i < 2; i++) {
//                    if (i == 0) {
//                        downLineModel.setStatus("0");
//                        getDataSearchCarsByNO(downLineModel);
//                    } else if (i == 1) {
//                        downLineModel.setStatus("1");
//                        getDataSearchCarsByNO(downLineModel);
//                    }
//                }
            }
        }
    }

    void refreshData() {
//        new Thread() {
//
//            @Override
//            public void run() {
//                handler.postDelayed(myRunnable, 100);
//            }
//        }.start();
//        Handler handler = new Handler();
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                getData(1);//环保队列
//            }
//        }, 180);//后执行Runnable中的run方法
        getData(0);//安检队列
        getData(1);//环保队列
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                getData(1);//环保队列
//            }
//        }, 110);//后执行Runnable中的run方法
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mergeAnHuanCarsList();
            }
        }, 2500);//后执行Runnable中的run方法

    }

    void schearCarByNO(String carNO) {
        downLineModel = new DownLineModel();
        downLineModel.setType("0");
        downLineModel.setPlateNO(carNO);
        searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                downLineModel.setStatus("0");
                getDataSearchCarsByNO(downLineModel);
            } else if (i == 1) {
                downLineModel.setStatus("1");
                getDataSearchCarsByNO(downLineModel);
            }
        }
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                getData(1);//环保队列
//            }
//        }, 800);//后执行Runnable中的run方法
        Handler handler2 = new Handler();
        handler2.postDelayed(new Runnable() {
            @Override
            public void run() {
                mergeSearCarsList();
            }
        }, 200);//后执行Runnable中的run方法

    }

    class MyRunnable implements Runnable {//内部类实现Runnable接口；

        @Override
        public void run() {//还是在Runnable重写的run()方法中更新界面；
//            text.setText("使用Handler更新了界面");
            getData(0);//安检队列
//            getData(1);//环保队列
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
    }

    //获取车辆列表根据选择的检测类型
    private void getDataCarsListByMode() {
        //检测模式 0:外检  F1 1：路试 R1 2：底盘动态 DC
        String car_url = "";
        switch (BaseApplication.JIANCE_MODE) {
            case 0:
                car_url = CAR_LIST_WAIJIAN;
                break;
            case 1:
                car_url = CAR_LIST_LUSHI;
                break;
            case 2:
                car_url = CAR_LIST_DIPAN;
                break;
            case 6:
                car_url = CAR_LIST_DIGOU;
                break;
            case 8:
                car_url = CAR_LIST_QINGDAO;
                break;
        }
//        if (carsInforModelList != null) {
//            carsInforModelList.clear();
//        }
        UtilsLog.e("getDataCarsListByMode---url==" + SharedPreferencesUtils.getIP(this) + car_url);
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + car_url).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
//                        UtilsLog.e("getDataCarsList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        carsInforModelList = new ArrayList<CarsInforModel>();
//                        UtilsLog.e("getDataCarsListByMode-newResult==" + newResult);
                        String logStr = "\n" + "安检--待检车辆列表-----" + "\n"
                                + "\n" + "result" + newResult + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModelList = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            if (carsInforModelList != null && carsInforModelList.size() > 0) {

//                                for (int i = 0; i < carsInforModelList.size(); i++) {
//                                    adapterCarsList.add(carsInforModelList.get(i));
//                                }
                            } else {
//                                carsInforListAdapter.notifyDataSetChanged();
                                UtilsLog.e("getDataCarsListByMode-result==" + "2222没有数据");
                            }
                        } else {
//                            carsInforListAdapter.notifyDataSetChanged();
                            UtilsLog.e("getDataCarsListByMode-result==" + "没有数据");
                        }
//                        getDataCarsListByMode_2();
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataCarsListByMode-onError==" + response.body());
                        String logStr = "\n" + "安检--待检车辆列表-----" + "\n"
                                + "\n" + "result" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //不自动刷新的查询
    //carNO 车牌号码
    private void getDataSearchCarsByNO(DownLineModel downLineModel) {
        Gson gson = new Gson();
        String json_str = gson.toJson(downLineModel);
        UtilsLog.e("getDataSearchCarsByNO---json_str==" + json_str);
        UtilsLog.e("getDataSearchCarsByNO---url==" + SharedPreferencesUtils.getIP(this) + SEARCH_CARS);
        String logStr = "\n" + "待检车辆列表--查询----请求" + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS
                + "\n" + "json" + json_str;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + SEARCH_CARS).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataSearchCarsByNO-newResult==" + newResult);

                        String logStr = "\n" + "待检车辆列表--查询----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + CARS_DOWN_LINE;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//C1Status  0就是未检测，1是合格，2是不合格
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            searChCarsList_one = new ArrayList<CarsInforModel>();
                            searChCarsList_one = JsonUtil.stringToArray(newResult, CarsInforModel[]
                                    .class);
                            if (searChCarsList_one != null && searChCarsList_one.size() > 0) {

                                for (int i = 0; i < searChCarsList_one.size(); i++) {
                                    switch (BaseApplication.JIANCE_MODE) {
                                        case 0:
                                            if (searChCarsList_one.get(i).getAppearanceStatus() == 0 ||
                                                    searChCarsList_one.get(i).getAppearanceStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE
                                                    || searChCarsList_one.get(i).getUCStatus().equals("0")
                                                    || searChCarsList_one.get(i).getNQStatus().equals("0")) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 1:
                                            if (searChCarsList_one.get(i).getRoadStatus() == 0 ||
                                                    searChCarsList_one.get(i).getRoadStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 2:
                                            if (searChCarsList_one.get(i).getDynamicStatus() == 0 ||
                                                    searChCarsList_one.get(i).getDynamicStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 6:
                                            if (!TextUtils.isEmpty(searChCarsList_one.get(i).getC1Status())) {
                                                if (searChCarsList_one.get(i).getC1Status().equals("0")) {
                                                    searChCarsFilterList.add(searChCarsList_one.get(i));
                                                }
                                            }
                                            break;
                                    }
                                }


//                                if (searChCarsFilterList != null && searChCarsFilterList.size() > 0) {
//                                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
//                                            searChCarsFilterList, CURRENT_CHECK_MODE);
//                                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
//                                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
//                                } else {
//                                    if (searChCarsFilterList != null) {
//                                        searChCarsFilterList.clear();
//                                    }
//                                    listShequgonggaoBaoxiu.setVisibility(View.GONE);
//                                }


                            } else {
                                listShequgonggaoBaoxiu.setVisibility(View.GONE);
                                Toast.makeText(instances, "没有查询到相关车辆", Toast
                                        .LENGTH_LONG).show();
                            }
                        } else {
                            listShequgonggaoBaoxiu.setVisibility(View.GONE);
                            UtilsLog.e("getDataSearchCarsByNO-result==" + "没有数据");
//                            Toast.makeText(instances, "没有查询到相关车辆", Toast
//                                    .LENGTH_LONG).show();
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataSearchCarsByNO-onError==" + response.body());
                        String logStr = "\n" + "待检车辆列表--查询----请求失败--error" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + CARS_DOWN_LINE;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //环保---获取车辆列表
    private void getDataCarsListHuanBao() {
//        if (huanBao_carsInforModelList != null) {
//            huanBao_carsInforModelList.clear();
//        }
        UtilsLog.e("环保队列---url==" + SharedPreferencesUtils.getIP(this) + JHUANBAO_CARS_LIST);
        String logStr = "\n" + "环保队列--待检车辆列表--查询----" + "\n"
                + "\n" + "url" + SharedPreferencesUtils.getIP(this) + JHUANBAO_CARS_LIST + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + JHUANBAO_CARS_LIST).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        huanBao_carsInforModelList = new ArrayList<HuanBaoModel>();
//                        UtilsLog.e("环保队列-newResult==" + newResult);
                        String logStr = "\n" + "环保队列--待检车辆列表--查询----" + "\n"
                                + "\n" + "result" + newResult + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            huanBao_carsInforModelList = JsonUtil.stringToArray(newResult, HuanBaoModel[].class);
                            if (huanBao_carsInforModelList != null && huanBao_carsInforModelList.size() > 0) {

                            } else {
                                UtilsLog.e("环保队列-result==" + "2222没有数据");
                            }
//                            UtilsLog.e("环保队列==" + huanBao_carsInforModelList.toString());
                        } else {
                            UtilsLog.e("环保队列-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("环保队列-onError==" + response.body());
                        String logStr = "\n" + "环保队列--待检车辆列表--查询--onError--" + "\n"
                                + "\n" + "result" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //合并安检-环保 两个队列
    void mergeAnHuanCarsList() {
        String logStr = "\n" + " -待检车辆列表--合并安检-环保 两个队列--mergeAnHuanCarsList--" + "\n";
        int huanbao_length = 0;//环保队列长度
        int anjian_length = 0;//安检队列长度
        if (huanBao_carsInforModelList != null && huanBao_carsInforModelList.size() > 0) {
            huanbao_length = huanBao_carsInforModelList.size();
            logStr += "\n" + "huanBao_carsInforModelList" + huanBao_carsInforModelList.toString() + "\n";
        } else {
            logStr += "\n" + "huanBao_carsInforModelList" + "===null" + "\n";
        }
        if (carsInforModelList != null && carsInforModelList.size() > 0) {
            anjian_length = carsInforModelList.size();
            logStr += "\n" + "carsInforModelList" + carsInforModelList.toString() + "\n";
        } else {
            logStr += "\n" + "carsInforModelList" + "===null" + "\n";
        }
//        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("环保队列长度===" + huanbao_length);
        UtilsLog.e("安检队列长度===" + anjian_length);
        if (huanbao_length == 0 && anjian_length == 0) {
            //环保、安检队列都没有数据 跳出此方法
            UtilsLog.e("00000000000000===");
            listShequgonggaoBaoxiu.setVisibility(View.GONE);
            return;
        }
        an_huan_carsList = new ArrayList<>();//并集--安检环保都有的
        an_huan_adapterList = new ArrayList<>();//adapter数据展示用的
        An_Huan_Model an_huan_model = null;
        if (CURRENT_CHECK_MODE.equals("F1")) {
            //外检
            UtilsLog.e("1111111111111111===");
            if (huanbao_length == 0 && anjian_length > 0) {
                UtilsLog.e("2222222222222222===");
                //只有安检队列
                //把安检队列与环保队列合并到一个队列 便于操作
                for (int i = 0; i < anjian_length; i++) {
                    CarsInforModel carsModel = carsInforModelList.get(i);
                    if (TextUtils.isEmpty(carsModel.getPlateRegion()) && TextUtils.isEmpty(carsModel.getPlateNO())) {
                        break;
                    }
                    String anjian_carNO = carsModel.getPlateRegion() + carsModel.getPlateNO();
                    an_huan_model = new An_Huan_Model();
                    if (!TextUtils.isEmpty(carsModel.getPlateExtra())) {
                        an_huan_model.setPlateExtra(carsModel.getPlateExtra());
                    }

                    an_huan_model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                    an_huan_model.setCarNo(anjian_carNO);
                    an_huan_model.setPlateFormSN(carsModel.getPlatformSN());
                    an_huan_model.setTimes(carsModel.getTimes());
                    an_huan_model.setTypeName(carsModel.getTypeName());
                    an_huan_model.setCarsInforModel(carsModel);
//                            an_huan_model.setHuanBaoModel(huanbaoModel);
                    if (!TextUtils.isEmpty(carsModel.getDetectDate())) {
                        an_huan_model.setDetectDate(carsModel.getDetectDate());
                    }
                    an_huan_carsList.add(an_huan_model);
                }

            } else if (huanbao_length > 0 && anjian_length == 0) {
                UtilsLog.e("3333333333333333===");
                //只有环保队列
//                for (int i = 0; i < huanbao_length; i++) {
//                    HuanBaoModel huanbaoModel = huanBao_carsInforModelList.get(i);
//                    if (TextUtils.isEmpty(huanbaoModel.getPlateRegion()) && TextUtils.isEmpty(huanbaoModel.getPlateNO())) {
//                        break;
//                    }
//                    String huanbao_carNO = huanbaoModel.getPlateRegion() +
//                            huanbaoModel.getPlateNO();
//                    an_huan_model = new An_Huan_Model();
//                    if (!TextUtils.isEmpty(huanbaoModel.getPlateExtra())) {
//                        an_huan_model.setPlateExtra(huanbaoModel.getPlateExtra());
//                    }
//                    an_huan_model.setIsAnHuan(1);//isAnHuan  0:安检  1：环保  2:两者都有
//                    an_huan_model.setCarNo(huanbao_carNO);
//                    an_huan_model.setPlateFormSN(huanbaoModel.getPlatformSN());
//                    an_huan_model.setTimes(huanbaoModel.getTimes());
//                    an_huan_model.setTypeName(huanbaoModel.getTypeName());
////                    an_huan_model.setCarsInforModel(carsModel);
//                    an_huan_model.setHuanBaoModel(huanbaoModel);
//                    if (!TextUtils.isEmpty(huanbaoModel.getDetectDate())) {
//                        an_huan_model.setDetectDate(huanbaoModel.getDetectDate());
//                    }
//                    an_huan_carsList.add(an_huan_model);
//                }
            } else if (huanbao_length > 0 && anjian_length > 0) {
                UtilsLog.e("444444444444444===");
                //既有安检队列也有环保队列
                //把安检队列与环保队列合并到一个队列 便于操作
                for (int i = 0; i < huanbao_length; i++) {
                    if (TextUtils.isEmpty(huanBao_carsInforModelList.get(i).getPlateRegion())
                            && TextUtils.isEmpty(huanBao_carsInforModelList.get(i).getPlateNO())) {
                        break;
                    }
                    String huanbao_carNO = huanBao_carsInforModelList.get(i).getPlateRegion() +
                            huanBao_carsInforModelList.get(i).getPlateNO();
                    String huanbao_carType = huanBao_carsInforModelList.get(i).getPlateType();
                    String huanbao_carVIN = huanBao_carsInforModelList.get(i).getVIN();
                    HuanBaoModel huanbaoModel = huanBao_carsInforModelList.get(i);
                    for (int j = 0; j < anjian_length; j++) {
                        CarsInforModel carsModel = carsInforModelList.get(j);
                        String anjian_carNO = carsInforModelList.get(j).getPlateRegion() +
                                carsInforModelList.get(j).getPlateNO();
                        String anjian_carType = carsInforModelList.get(j).getPlateType();
                        String anjian_carVIN = carsInforModelList.get(j).getVIN();
                        if (huanbao_carNO.equals(anjian_carNO) && huanbao_carType.equals(anjian_carType)
                                && huanbao_carVIN.equals(anjian_carVIN)) {
                            //是同一辆车
                            an_huan_model = new An_Huan_Model();
                            if (!TextUtils.isEmpty(carsModel.getPlateExtra())) {
                                an_huan_model.setPlateExtra(carsModel.getPlateExtra());
                            }
                            an_huan_model.setIsAnHuan(2);//isAnHuan  0:安检  1：环保  2:两者都有
                            an_huan_model.setCarNo(anjian_carNO);
                            an_huan_model.setPlateFormSN(carsModel.getPlatformSN());
                            an_huan_model.setTimes(carsModel.getTimes());
                            an_huan_model.setTypeName(carsModel.getTypeName());
                            an_huan_model.setCarsInforModel(carsModel);
                            an_huan_model.setHuanBaoModel(huanbaoModel);
                            an_huan_model.setDetectDate(huanbaoModel.getDetectDate());
                            an_huan_carsList.add(an_huan_model);
                        }
                    }
                }
            } else {
                UtilsLog.e("555555555555===");
                listShequgonggaoBaoxiu.setVisibility(View.GONE);
            }
            if (huanbao_length == 0 && anjian_length == 0) {
                UtilsLog.e("6666666666666666===");
                listShequgonggaoBaoxiu.setVisibility(View.GONE);
            } else {
                UtilsLog.e("7777777777777777===");
                if (an_huan_carsList != null && an_huan_carsList.size() > 0) {
                    UtilsLog.e("有并集=============");
//                    for (int i = 0; i < an_huan_carsList.size(); i++) {
//                        UtilsLog.e("有并集======an_huan_carsList=======" + an_huan_carsList.get(i).toString());
//                    }
//                if (CURRENT_CHECK_MODE.equals("F1")) {
                    //把环保队列与并集的差集加进去
                    An_Huan_Model model = null;
                    for (int i = 0; i < huanbao_length; i++) {
                        boolean one = false;
                        HuanBaoModel huanbaoModel = huanBao_carsInforModelList.get(i);
                        String huanbao_carNO = huanbaoModel.getPlateRegion() +
                                huanbaoModel.getPlateNO();
                        for (int j = 0; j < an_huan_carsList.size(); j++) {
                            An_Huan_Model ahModel = an_huan_carsList.get(j);
                            String ah_carNO = ahModel.getCarNo();
                            if (huanbao_carNO.equals(ah_carNO)) {
                                one = false;
                                break;
                            } else {
                                one = true;
                            }
                        }
                        if (one) {
                            model = new An_Huan_Model();
                            if (!TextUtils.isEmpty(huanbaoModel.getPlateExtra())) {
                                model.setPlateExtra(huanbaoModel.getPlateExtra());
                            }
                            model.setCarNo(huanbao_carNO);
                            model.setPlateFormSN(huanbaoModel.getPlatformSN());
                            model.setTimes(huanbaoModel.getTimes());
                            model.setTypeName(huanbaoModel.getTypeName());
                            model.setHuanBaoModel(huanbaoModel);
                            model.setDetectDate(huanbaoModel.getDetectDate());
                            model.setIsAnHuan(1);//isAnHuan  0:安检  1：环保  2:两者都有
                            an_huan_adapterList.add(model);
                        }
                    }
                    //把安检队列与并集的差集加进去
                    for (int i = 0; i < carsInforModelList.size(); i++) {
                        boolean one = false;
                        CarsInforModel carsModel = carsInforModelList.get(i);
                        String an_carNO = carsModel.getPlateRegion() +
                                carsModel.getPlateNO();
                        for (int j = 0; j < an_huan_carsList.size(); j++) {
                            An_Huan_Model ahModel = an_huan_carsList.get(j);
                            String ah_carNO = ahModel.getCarNo();
                            if (an_carNO.equals(ah_carNO)) {
                                one = false;
                                break;
                            } else {
                                one = true;
                            }
                        }
                        if (one) {
                            model = new An_Huan_Model();
                            if (!TextUtils.isEmpty(carsModel.getPlateExtra())) {
                                model.setPlateExtra(carsModel.getPlateExtra());
                            }
                            model.setCarNo(an_carNO);
                            model.setPlateFormSN(carsModel.getPlatformSN());
                            model.setTimes(carsModel.getTimes());
                            model.setTypeName(carsModel.getTypeName());
                            model.setCarsInforModel(carsModel);
                            model.setDetectDate(carsModel.getDetectDate());
                            model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                            an_huan_adapterList.add(model);
                        }
                    }

                    //把并集加进去
                    an_huan_adapterList.addAll(an_huan_carsList);

                    //第一个写法
                    Collections.sort(an_huan_adapterList, new Comparator<An_Huan_Model>() {
                        @Override
                        public int compare(An_Huan_Model o1, An_Huan_Model o2) {
                            return o2.getDetectDate().compareTo(o1.getDetectDate());
                        }
                    });
                    Logger.e("有并集========AAAAA====="+an_huan_adapterList.toString());
//                    UtilsLog.e("有并集========AAAAA====="+an_huan_adapterList.toString());
                    List<An_Huan_Model> an_huan_adapterList22 = new ArrayList<An_Huan_Model>();
                    an_huan_adapterList22=an_huan_adapterList.stream().filter(b->b.getIsAnHuan()!=1).collect(Collectors.toList());
                    Logger.e("有并集========BBBB====="+an_huan_adapterList22.toString());
                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                            an_huan_adapterList22, CURRENT_CHECK_MODE);
//                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
//                            an_huan_adapterList, CURRENT_CHECK_MODE);
                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                } else {
                    UtilsLog.e("没有并集=============");
                    UtilsLog.e("安检--环保--没有并集----");
                    An_Huan_Model model = null;
                    for (int i = 0; i < carsInforModelList.size(); i++) {
                        CarsInforModel carsModel = carsInforModelList.get(i);
                        String an_carNO = carsModel.getPlateRegion() +
                                carsModel.getPlateNO();
                        model = new An_Huan_Model();
                        if (!TextUtils.isEmpty(carsModel.getPlateExtra())) {
                            model.setPlateExtra(carsModel.getPlateExtra());
                        }
                        model.setCarNo(an_carNO);
                        model.setPlateFormSN(carsModel.getPlatformSN());
                        model.setTimes(carsModel.getTimes());
                        model.setTypeName(carsModel.getTypeName());
                        model.setCarsInforModel(carsModel);
                        model.setDetectDate(carsModel.getDetectDate());
                        model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                        an_huan_adapterList.add(model);
                    }
                    for (int i = 0; i < huanbao_length; i++) {
                        HuanBaoModel huanbaoModel = huanBao_carsInforModelList.get(i);
                        String huanbao_carNO = huanbaoModel.getPlateRegion() +
                                huanbaoModel.getPlateNO();
                        model = new An_Huan_Model();
                        if (!TextUtils.isEmpty(huanbaoModel.getPlateExtra())) {
                            model.setPlateExtra(huanbaoModel.getPlateExtra());
                        }
                        model.setCarNo(huanbao_carNO);
                        model.setPlateFormSN(huanbaoModel.getPlatformSN());
                        model.setTimes(huanbaoModel.getTimes());
                        model.setTypeName(huanbaoModel.getTypeName());
                        model.setDetectDate(huanbaoModel.getDetectDate());
                        model.setHuanBaoModel(huanbaoModel);
                        model.setIsAnHuan(1);//isAnHuan  0:安检  1：环保  2:两者都有
                        an_huan_adapterList.add(model);
                    }

                    //第一个写法
                    Collections.sort(an_huan_adapterList, new Comparator<An_Huan_Model>() {
                        @Override
                        public int compare(An_Huan_Model o1, An_Huan_Model o2) {
                            return o2.getDetectDate().compareTo(o1.getDetectDate());
                        }
                    });
                    List<An_Huan_Model> an_huan_adapterList22 = new ArrayList<An_Huan_Model>();
                    an_huan_adapterList22=an_huan_adapterList.stream().filter(b->b.getIsAnHuan()!=1).collect(Collectors.toList());
                    Logger.e("有并集========BBBB====="+an_huan_adapterList22.toString());
                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                            an_huan_adapterList22, CURRENT_CHECK_MODE);
//                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
//                            an_huan_adapterList, CURRENT_CHECK_MODE);
                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                }
            }
        } else {
            UtilsLog.e("88888888888888===");
            //除了外检之外的
            UtilsLog.e("除了外检之外的=============");
            An_Huan_Model model = null;
            for (int i = 0; i < carsInforModelList.size(); i++) {
                CarsInforModel carsModel = carsInforModelList.get(i);
                String an_carNO = carsModel.getPlateRegion() +
                        carsModel.getPlateNO();
                model = new An_Huan_Model();
                if (!TextUtils.isEmpty(carsModel.getPlateExtra())) {
                    model.setPlateExtra(carsModel.getPlateExtra());
                }
                model.setCarNo(an_carNO);
                model.setPlateFormSN(carsModel.getPlatformSN());
                model.setTimes(carsModel.getTimes());
                model.setTypeName(carsModel.getTypeName());
                model.setCarsInforModel(carsModel);
                model.setDetectDate(carsModel.getDetectDate());
                model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                an_huan_adapterList.add(model);
            }

            Collections.sort(an_huan_adapterList, new Comparator<An_Huan_Model>() {
                @Override
                public int compare(An_Huan_Model o1, An_Huan_Model o2) {
                    return o2.getDetectDate().compareTo(o1.getDetectDate());
                }
            });
            carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                    an_huan_adapterList, CURRENT_CHECK_MODE);
            listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
            listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
        }
//        for (int i = 0; i < an_huan_adapterList.size(); i++) {
//            UtilsLog.e("终极队列==(" + i + ")==" + an_huan_adapterList.get(i).toString());
//        }
    }


    //合并 查询 两个队列
    void mergeSearCarsList() {
        String logStr = "\n" + " -待检车辆列表--合并 查询 两个队列--mergeSearCarsList--" + "\n";
        int huanbao_length = 0;//环保队列长度
        int anjian_length = 0;//安检队列长度
        if (huanBao_carsInforModelList != null && huanBao_carsInforModelList.size() > 0) {
            huanbao_length = huanBao_carsInforModelList.size();
            logStr += "\n" + "huanBao_carsInforModelList" + huanBao_carsInforModelList.toString() + "\n";
        } else {
            logStr += "\n" + "huanBao_carsInforModelList" + "===null" + "\n";
        }
        if (searChCarsFilterList != null && searChCarsFilterList.size() > 0) {
            anjian_length = searChCarsFilterList.size();
            logStr += "\n" + "carsInforModelList" + carsInforModelList.toString() + "\n";
        } else {
            logStr += "\n" + "carsInforModelList" + "===null" + "\n";
        }
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        if (huanbao_length == 0 || anjian_length == 0) {
            return;
        }
        an_huan_carsList = new ArrayList<>();
        An_Huan_Model an_huan_model = null;
        for (int i = 0; i < huanbao_length; i++) {
            String huanbao_carNO = huanBao_carsInforModelList.get(i).getPlateRegion() +
                    huanBao_carsInforModelList.get(i).getPlateNO();
            String huanbao_carType = huanBao_carsInforModelList.get(i).getPlateType();
            String huanbao_carVIN = huanBao_carsInforModelList.get(i).getVIN();
            HuanBaoModel huanbaoModel = huanBao_carsInforModelList.get(i);
            for (int j = 0; j < anjian_length; j++) {
                CarsInforModel carsModel = searChCarsFilterList.get(j);
                String anjian_carNO = searChCarsFilterList.get(j).getPlateRegion() +
                        searChCarsFilterList.get(j).getPlateNO();
                String anjian_carType = searChCarsFilterList.get(j).getPlateType();
                String anjian_carVIN = searChCarsFilterList.get(j).getVIN();
                if (huanbao_carNO.equals(anjian_carNO) && huanbao_carType.equals(anjian_carType)
                        && huanbao_carVIN.equals(anjian_carVIN)) {
                    //是同一辆车
                    an_huan_model = new An_Huan_Model();
                    an_huan_model.setIsAnHuan(2);//isAnHuan  0:安检  1：环保  2:两者都有
                    an_huan_model.setCarNo(anjian_carNO);
                    an_huan_model.setPlateFormSN(carsModel.getPlatformSN());
                    an_huan_model.setTimes(carsModel.getTimes());
                    an_huan_model.setTypeName(carsModel.getTypeName());
                    an_huan_model.setCarsInforModel(carsModel);
                    an_huan_model.setHuanBaoModel(huanbaoModel);
                    an_huan_carsList.add(an_huan_model);
                }
            }
        }
        if (!CURRENT_CHECK_MODE.equals("F1")) {
            if (an_huan_adapterList != null && an_huan_adapterList.size() > 0) {
                an_huan_adapterList = new ArrayList<>();
                An_Huan_Model model = null;
                for (int i = 0; i < searChCarsFilterList.size(); i++) {
                    CarsInforModel carsModel = searChCarsFilterList.get(i);
                    String an_carNO = carsModel.getPlateRegion() +
                            carsModel.getPlateNO();
                    model = new An_Huan_Model();
                    model.setCarNo(an_carNO);
                    model.setPlateFormSN(carsModel.getPlatformSN());
                    model.setTimes(carsModel.getTimes());
                    model.setTypeName(carsModel.getTypeName());
                    model.setCarsInforModel(carsModel);
                    model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                    an_huan_adapterList.add(model);
                }
                carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                        an_huan_adapterList, CURRENT_CHECK_MODE);
                listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
            } else {
                listShequgonggaoBaoxiu.setVisibility(View.GONE);
            }
        } else {
            an_huan_adapterList = new ArrayList<>();
            if (an_huan_carsList != null && an_huan_carsList.size() > 0) {
                if (CURRENT_CHECK_MODE.equals("F1")) {
                    An_Huan_Model model = null;
                    //把安检队列与并集的差集加进去
                    for (int i = 0; i < searChCarsFilterList.size(); i++) {
                        boolean one = false;
                        CarsInforModel carsModel = searChCarsFilterList.get(i);
                        String an_carNO = carsModel.getPlateRegion() +
                                carsModel.getPlateNO();
                        for (int j = 0; j < an_huan_carsList.size(); j++) {
                            An_Huan_Model ahModel = an_huan_carsList.get(j);
                            String ah_carNO = ahModel.getCarNo();
                            if (an_carNO.equals(ah_carNO)) {
                                one = false;
                                break;
                            } else {
                                one = true;

                            }
                        }
                        if (one) {
                            model = new An_Huan_Model();
                            model.setCarNo(an_carNO);
                            model.setPlateFormSN(carsModel.getPlatformSN());
                            model.setTimes(carsModel.getTimes());
                            model.setTypeName(carsModel.getTypeName());
                            model.setCarsInforModel(carsModel);
                            model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                            an_huan_adapterList.add(model);
                        }
                    }

                    //把并集加进去
                    an_huan_adapterList.addAll(an_huan_carsList);

                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                            an_huan_adapterList, CURRENT_CHECK_MODE);
                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                } else {
                    //把安检队列与并集的差集加进去
                    An_Huan_Model model = null;
                    for (int i = 0; i < searChCarsFilterList.size(); i++) {
                        CarsInforModel carsModel = searChCarsFilterList.get(i);
                        String an_carNO = carsModel.getPlateRegion() +
                                carsModel.getPlateNO();
                        model = new An_Huan_Model();
                        model.setCarNo(an_carNO);
                        model.setPlateFormSN(carsModel.getPlatformSN());
                        model.setTimes(carsModel.getTimes());
                        model.setTypeName(carsModel.getTypeName());
                        model.setCarsInforModel(carsModel);
                        model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                        an_huan_adapterList.add(model);
                    }
                    //把并集加进去
//                an_huan_adapterList.addAll(an_huan_carsList);
                    carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                            an_huan_adapterList, CURRENT_CHECK_MODE);
                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                }
            } else {
                UtilsLog.e("安检--环保--没有并集----");
                An_Huan_Model model = null;
                for (int i = 0; i < searChCarsFilterList.size(); i++) {
                    CarsInforModel carsModel = searChCarsFilterList.get(i);
                    String an_carNO = carsModel.getPlateRegion() +
                            carsModel.getPlateNO();
                    model = new An_Huan_Model();
                    model.setCarNo(an_carNO);
                    model.setPlateFormSN(carsModel.getPlatformSN());
                    model.setTimes(carsModel.getTimes());
                    model.setTypeName(carsModel.getTypeName());
                    model.setCarsInforModel(carsModel);
                    model.setIsAnHuan(0);//isAnHuan  0:安检  1：环保  2:两者都有
                    an_huan_adapterList.add(model);
                }
                //把并集加进去
//                an_huan_adapterList.addAll(an_huan_carsList);
                carsInforListAdapter2 = new CarsInforListAdapter2(DaiJianCarsActivity.this,
                        an_huan_adapterList, CURRENT_CHECK_MODE);
                listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter2);
                listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
            }
//            for (int i = 0; i < an_huan_adapterList.size(); i++) {
//                UtilsLog.e("终极队列==(" + i + ")==" + an_huan_adapterList.get(i).toString());
//            }
        }
    }

}